#!/bin/bash
##  --no-version-check  Do not check for bash version. USE WITH CAUTION!

#
# SYSTEM CHECKS
#
function BashVersionGE () {
	local  V  PASSED  HI="${1:-0}"  LO="${2:-0}"
	PASSED="false"
	for V in "${BASH_ARGV[@]}"; do # the arguments here are in reversed order
		[[ "$V" = "--" ]] && PASSED="false" # clear previously found options
		[[ "$V" = "--no-version-check" ]] && PASSED="true"
	done
	$PASSED && return 0 # --no-version-check found
	if (( ${BASH_VERSINFO[0]} == $HI )); then
		(( PASSED = (${BASH_VERSINFO[1]} >= $LO) ? 0 : 1 ))
	else
		(( PASSED = (${BASH_VERSINFO[0]} > $HI) ? 0 : 1 ))
	fi
	return $PASSED
}
if ! BashVersionGE 3 1; then # we have to check for bash version as early as possible to avoid possible parse errors
	echo "WARNING! Bash version check failed. This software can (and probably will)"
	echo "  behave strangely, and DATA LOSS MAY OCCUR. If you still want to run it"
	echo "  (you have been warned!), use --no-version-check option."
	echo "  Found bash version: ${BASH_VERSION}; required bash version: 3.1 or higher."
	exit 1
fi




#function SubArray () {
	# offset >= 0 && length > 0: offset..offset+length
	# offset >= 0 && length < 0: offset..count-length
	# offset < 0 && length > 0: count-offset..count-offset+length
	# offset < 0 && length < 0: count-offset-length..count-offset

#	(( $# < 2 )) && Usage "<array> <offset> [<length>]"
#	local  PTR="$1[@]"  OFFSET="$2"  LENGTH="${3:-0}"
#	eval "local OLENGTH=\${#$PTR}"
#	(( ($LENGTH < 1) && (LENGTH = $OLENGTH - $OFFSET + $LENGTH) ))
#	local NEW=( "${!PTR : $OFFSET : $LENGTH}" )

#	ArrayValues NEW

#}

#function InArray () {
#	GNUOptionsFromString "$@"
#	(( ${#CMDLINE_PARAMS[*]} > 3 )) || Usage "[--regex] <array> <value>"
#	local VALUE OP="=" PTR="${CMDLINE_PARAMS[0]}[@]" PATTERN="${CMDLINE_PARAMS[1]}"
#	for VALUE in "${CMDLINE_OPT_NAMES[*]}"; do # we can't recurse here, so we have no choice rather than parse these options
#		(( "regex" = "$VALUE" )) && OP="=~" && break;
#	done
#	for VALUE in "${!PTR}"; do
#		eval [[ "$VALUE" $OP "$PATTERN" ]] && return 0 # found it!
#	done
#	return 1 # not found
#}
